package org.jdemo.util;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Properties;

/**
 * PropertiesResource
 *
 * @author longlin(longlin@cyou-inc.com)
 * @date 2013-9-16
 * @since V1.0
 */
public class PropertiesResource extends Properties {
    private static final long serialVersionUID = -6756487269283140005L;

    public PropertiesResource(Properties props) {
        this.putAll(props);
    }

    public PropertiesResource(String props) {
        try {
            Properties p = new Properties();
            p.load(PropertiesResource.class.getResourceAsStream(props));
            this.putAll(p);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String getString(Object key) {
        return (String) get(key);
    }

    public boolean getBoolean(Object key) {
        return Boolean.parseBoolean(getString(key));
    }

    public int getInteger(Object key) {
        return Integer.parseInt(getString(key));
    }

    public long getLong(Object key) {
        return Long.parseLong(getString(key));
    }

    public float getFloat(Object key) {
        return Float.parseFloat(getString(key));
    }

    public double getDouble(Object key) {
        return Double.parseDouble(getString(key));
    }

    public BigDecimal getBigDecimal(Object key) {
        return new BigDecimal(getString(key));
    }
}
